<?php
namespace workin\controllers;

use common\components\tools\Tools;
use common\components\tools\Zip;
use workin\models\User;
use Yii;
use yii\base\InvalidParamException;
use yii\helpers\FileHelper;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\LoginForm;
use workin\models\PasswordResetRequestForm;
use workin\models\ResetPasswordForm;
use workin\models\SignupForm;
use workin\models\ContactForm;

/**
 * Site controller
 */
class SiteController extends Controller
{
    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

    /**
     * Displays homepage.
     *
     * @return mixed
     */
    public function actionIndex()
    {
        return $this->render('index');
    }

    public function actionTest()
    {
        return $this->render('test1');
    }

    public function actionLogin()
    {
        if (Yii::$app->user->isGuest){
            $user = User::findOne(['u_name'=>Yii::$app->request->get('u_name'), 'u_password'=>Yii::$app->request->get('u_password')]);
            if (Yii::$app->user->login($user, 3600)){
                return $this->goBack();
            }
        }
    }

    public function actionLogout()
    {
        Yii::$app->user->logout();
        return $this->goHome();
    }
}
